home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / newlooklib.lha / newlook / initnewwindow.c < prev    next >
C/C++ Source or Header  |  1993-11-06  |  3KB  |  111 lines

  1. /*
  2.  *  INITNEWWINDOW.C
  3.  */
  4.  
  5. #include "newlook.h"
  6.  
  7. #ifndef AUTOSCROLL
  8. #define AUTOSCROLL 0x4000  /* V36+ */
  9. #endif /* !AUTOSCROLL */
  10.  
  11. extern BOOL GetScreenData( APTR, UWORD, UWORD, struct Screen * );
  12.  
  13. /*
  14.  * BUGS
  15.  *   Ich habe keinen Plan, wie ich die Breite des rechten WindowBorders
  16.  *   rausfinden soll, wenn das Window ein SizeGadget hat.
  17.  */
  18.  
  19. struct NewWindow *InitNewWindow(nw, title, w,h, idcmp,flags, glist)
  20.  
  21. struct NewWindow *nw;  /* ... will be allocated if nw == NULL */
  22. UBYTE *title;
  23. WORD w,h;              /* inner (!) window dimensions */
  24. ULONG idcmp, flags;
  25. struct Gadget *glist;
  26. {
  27.   if(!nw)
  28.   {
  29.     if(nw= (struct NewWindow *)SmartAllocate(NEWWINDOWSIZE))
  30.       nw->Screen= (struct Screen *)NULL;
  31.   }
  32.  
  33.   if(nw)
  34.   {
  35.     struct Screen sbuf, *s= nw->Screen;
  36.  
  37.     if(!s)
  38.     {
  39.       nw->Type= (UWORD)WBENCHSCREEN;
  40.  
  41.       if(GetScreenData(&sbuf, sizeof(struct Screen), nw->Type, NULL))
  42.       {
  43.         /* GetScreenData() lies about dimensions */
  44.         sbuf.Width  = sbuf.ViewPort.DWidth;
  45.         sbuf.Height = sbuf.ViewPort.DHeight;
  46.         s= &sbuf;
  47.       }
  48.     }
  49.     /* else nw->Type must be set by the caller !!! */
  50.  
  51.     /* set parameter values */
  52.     nw->Width  = w;
  53.     nw->Height = h;
  54.  
  55.     if(s)
  56.     {
  57.       nw->Width  += s->WBorLeft + s->WBorRight;
  58.       nw->Height += s->WBorTop  + s->RastPort.TxHeight+1 + s->WBorBottom;
  59.  
  60.       /*
  61.        *  If we're going to open on an AUTOSCROLL Screen it is not
  62.        *  wise to appear at a fix position so we'll try to pop up
  63.        *  near the current location of the mouse pointer...
  64.        */
  65.  
  66.       if(s->Flags & AUTOSCROLL)
  67.       {
  68.         /* pop up under the mouse */
  69.         if((nw->LeftEdge= s->MouseX - nw->Width/2) < 0)
  70.           nw->LeftEdge= 0;
  71.         else if(nw->LeftEdge + nw->Width > s->Width)
  72.           nw->LeftEdge= s->Width - nw->Width;
  73.  
  74.         if((nw->TopEdge= s->MouseY - nw->Height/2) < 0)
  75.           nw->TopEdge= 0;
  76.         else if(nw->TopEdge+nw->Height > s->Height)
  77.           nw->TopEdge= s->Height - nw->Height;
  78.       }
  79.       else /* !AUTOSCROLL */
  80.       {
  81.         /* center window on screen */
  82.         nw->LeftEdge = (s->Width - nw->Width)/2;
  83.         nw->TopEdge  = (s->Height - nw->Height)/2;
  84.       }
  85.     }
  86.     else /* !Screen */
  87.     {
  88.       nw->LeftEdge  =
  89.       nw->TopEdge   = (WORD)0L;
  90.     }
  91.  
  92.     /* parameter values */
  93.     nw->IDCMPFlags  = idcmp;
  94.     nw->Flags       = flags;
  95.     nw->FirstGadget = glist;
  96.     nw->Title       = title;
  97.  
  98.     /* default values */
  99.     nw->DetailPen   = (UBYTE)0L;
  100.     nw->BlockPen    = (UBYTE)1L;
  101.     nw->CheckMark   = (struct Image *)NULL;
  102.     nw->BitMap      = (struct BitMap *)NULL;
  103.     nw->MinWidth    = 
  104.     nw->MinHeight   = (WORD)0L;
  105.     nw->MaxWidth    =
  106.     nw->MaxHeight   = (UWORD)0L;
  107.   }
  108.  
  109.   return nw;
  110. }
  111.